﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using IDAL;

public partial class UrlGroup : System.Web.UI.Page
{
    public int AddAndUpdateSign = 0;
    public int UrlGroupId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["AdminName"] == null)
            Response.Redirect("login.aspx");

        if (!Page.IsPostBack)
        {
            gdvList.DataSource = BLL.BUrlGroup.GetMyList();
            string[] keys ={ "UrlGroupID" };
            gdvList.DataKeyNames = keys;
            gdvList.DataBind();
            
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Entities.UrlGroup group = new Entities.UrlGroup();
        group.UrlGroup = this.txtUrlGroup.Text.Trim();
        group.Comment = txtComment.Text.Trim();
        BLL.BUrlGroup.Insert(group);
       
        Response.Redirect("UrlGroup.aspx");
    }

    protected void gdvList_RowEditing(object sender, GridViewEditEventArgs e)
    {
        int id = Convert.ToInt32(gdvList.DataKeys[e.NewEditIndex].Value);
        Entities.UrlGroup group = new Entities.UrlGroup();
        Entities.UrlGroup urlgroup = BLL.BUrlGroup.GetById(id);

        txtUrlGroup.Text = urlgroup.UrlGroup;
        txtComment.Text = urlgroup.Comment;
        AddAndUpdateSign = 1;
        UrlGroupIdHidden.Value = id.ToString();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Entities.UrlGroup urlgroup = BLL.BUrlGroup.GetById(int.Parse(UrlGroupIdHidden.Value));
        urlgroup.UrlGroup = this.txtUrlGroup.Text.Trim();
        urlgroup.Comment = txtComment.Text.Trim();
        BLL.BUrlGroup.Update(urlgroup);
        Response.Redirect("UrlGroup.aspx");
    }
    //protected void gdvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
    //{
    //    int id = Convert.ToInt32(gdvList.DataKeys[e.RowIndex].Value);
    //    Entities.UrlGroup urlgroup = BLL.BUrlGroup.GetById(id);
    //    BLL.BUrlGroup.Delete(urlgroup);
    //    Response.Redirect("UrlGroup.aspx");
    //}
    protected void gdvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gdvList.PageIndex = e.NewPageIndex;
        gdvList.DataSource = BLL.BUrlGroup.GetMyList();
        string[] keys ={ "UrlGroupID" };
        gdvList.DataKeyNames = keys;
        gdvList.DataBind();
    }
}
